using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;

namespace IQIGame.Onigao.Game.Editors
{
    public static class UIToolsEditor
    {

        [MenuItem("Assets/Copy UI Prefab Path", priority = 20)]
        static void CopyTransPath()
        {
            var guids = Selection.assetGUIDs;
            if (guids.Length <= 0)
            {
                return;
            }

            string assetPath = AssetDatabase.GUIDToAssetPath(guids[0]);

            var match = Regex.Match(assetPath, @".+03_Prefabs/UI/(.+)");

            if (match.Success)
            {
                string content = match.Groups[1].Value;
                GUIUtility.systemCopyBuffer = content;
            }

        }

        public static string GetUIPrefabPath(Transform trans)
        {
            if (null == trans) return string.Empty;
            if (trans.name == "03_Prefabs")
            {
                return string.Empty;
            }

            var parent = GetUIPrefabPath(trans.parent);
            if (string.IsNullOrEmpty(parent))
            {
                return trans.name;
            }
            else
            {
                return parent + "/" + trans.name;
            }
        }

    }
}
